$(function(){
	var count = 0;
	var num = 0;
	$('#btn01').on('click', function(){
		refreshCount(++count);
		if (this.promise_ && this.promise_.state() === 'pending') {
			return;
		}
		return this.promise_ = $.ajax({
			type: 'POST',
			url: '/his/repeatedSubmission',
			data: {'who' : 'repeatedSubmission'},
			dataType: 'json',
			success: function(data){
				if(data){
					appendConsole( "data is " + data , ++num);
				}else{
					$('#console').empty();
					$('#console').html("data is " + data);
				}
			}
		});
	});
});

function leftPad(str, length, separate) {
	var separate = separate || '_';
	var length = length || 5;
	var str = str+"";
	if(str.length >= length){
		return str+": ";
	}
	var content = "";
	for(var i=length; i>str.length; i--){
		content = content + separate;
	}
	content = content + str + ": ";
	return content;
}

function appendConsole(content, num) {
	var old = $('#console').html() + "<br>";
	content = leftPad(num) + content;
	$('#console').html(old + content);
}

function refreshCount(count) {
	var el_count = $('#id_count');
	el_count.empty();
	el_count.html(count);
}